﻿using Omabar.BLL;
using Omabar.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Omabar.CMS.Mobile
{
    public partial class RouteList : System.Web.UI.Page
    {
        protected List<ROUTE> routes;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Route_BLL bll = new Route_BLL();
                //string keywords = Request["keywords"];
                int pageNo = string.IsNullOrEmpty(Request["pageno"]) ? 1 : int.Parse(Request["pageno"]);

                string filter = string.Empty;
                string key = string.IsNullOrEmpty(Request["key"]) ? "" : Request["key"].ToUpper();

                if (key == "THEME")
                {
                    string themeid = Request["value"];
                    filter = string.Format(" where ROUTE_ID IN (SELECT ROUTE_ID FROM ROUTE_THEME WHERE THEME_ID = '{0}')", themeid);
                }
                else if (key == "COUNTRY")
                {
                    string cn = Request["value"];
                    filter = string.Format(" where ROUTE_ID IN (SELECT DISTINCT(ROUTE_ID) FROM ROUTE_COUNTRY where ROUTE_COUNTRY_NAME='{0}')", cn);
                }
                else if (key == "ROUTE_ELABORATE")
                {
                    filter= " where ROUTE_ELABORATE = 1";
                }
                else if (key == "ROUTE_HOT")
                {
                    filter = " where ROUTE_HOT >= 90";
                }
                else if(key== "ROUTE_NAME")
                {
                    string routeName = Request["value"];
                    filter = " where ROUTE_NAME like '%" + routeName + "%'";
                }
                else
                {
                    filter = "";
                }

                string sqllist = "select Top 1000 ROUTE_ID,ROUTE_NAME,ROUTE_DES,ROUTE_CHENGDU,ROUTE_BEIJING,ROUTE_ELSECITY,ROUTE_CHARACTERISTIC,ROUTE_DAYS,ROUTE_PRICE,ROUTE_DATE_START,ROUTE_DATE_END,ROUTE_HOT,ROUTE_BAK,ROUTE_ELABORATE,ROUTE_ORIGINAL from (select row_number() over(order by ROUTE_NAME desc) as rownumber,* from ROUTE {0}) A where rownumber > {1}";
                //string sqlcount = "select count(*) from ROUTE";
                //if (!string.IsNullOrEmpty(keywords))
                //{
                //    string filter = string.Format(" where ROUTE_NAME like '%{0}%'", keywords);
                //    sqlcount += filter;
                //    sqllist = string.Format(sqllist, filter, (pageNo - 1) * 10);
                //}

                sqllist = string.Format(sqllist, filter, (pageNo - 1) * 10);
                routes = bll.GetModels(sqllist);
                if (routes == null) routes = new List<ROUTE>();

                
            }
        }
    }
}